package com.itheima.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

/**
 * @author by itheima
 * @Date 2022/4/22
 * @Description 定会spring整合mybatis的配置类
 */
//@Configuration
public class MybatisConfig {

    /**
     * 构建会话工厂bena，底层是对会话工厂的封装
     * 摆脱了xml核心配置
     * @return
     */
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean( DataSource dataSource){
        //构建对象
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        //设置数据源
        factoryBean.setDataSource(dataSource);
        //批量给实体类取别名，作用等价于：
        factoryBean.setTypeAliasesPackage("com.itheima.domain");
        return factoryBean;
    }

    /**
     * 配置扫描接口，动态生成接口的代理对象，同时将代理对象加入ioc容器中
     * @return
     */
//    @Bean
//    public MapperScannerConfigurer mapperScannerConfigurer(){
//        MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();
//        //scannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
//        scannerConfigurer.setBasePackage("com.itheima.dao");
//        return scannerConfigurer;
//    }




}
